home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / util / moni / Scout-src.lha / source / objects / scout_memory_detail.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-09-17  |  10.0 KB  |  273 lines

  1. /**
  2.  * Scout - The Amiga System Monitor
  3.  *
  4.  *------------------------------------------------------------------
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * You must not use this source code to gain profit of any kind!
  21.  *
  22.  *------------------------------------------------------------------
  23.  *
  24.  * @author Andreas Gelhausen
  25.  * @author Richard Körber <rkoerber@gmx.de>
  26.  */
  27.  
  28. #include "system_headers.h"
  29.  
  30. static __asm __saveds LONG memmorelist_dsp2func(register __a2 Object *obj, register __a1 struct NList_DisplayMessage *msg, register __a0 struct Hook *hook)
  31. {
  32.     struct MemoryFreeEntry *mfe = (struct MemoryFreeEntry *)msg->entry;
  33.  
  34.     if (mfe) {
  35.         msg->strings[0] = mfe->mfe_Lower;
  36.         msg->strings[1] = mfe->mfe_Upper;
  37.         msg->strings[2] = mfe->mfe_Size;
  38.     } else {
  39.         msg->strings[0] = "Lower";
  40.         msg->strings[1] = "Upper";
  41.         msg->strings[2] = "Size";
  42.         msg->preparses[0] = MUIX_B;
  43.         msg->preparses[1] = MUIX_B;
  44.         msg->preparses[2] = MUIX_B;
  45.     }
  46.  
  47.     return 0;
  48. }
  49.  
  50. MakeHook(memmorelist_dsp2hook, memmorelist_dsp2func);
  51.  
  52. static LONG memmorelist_cmp2colfunc( struct MemoryFreeEntry *mfe1,
  53.                                      struct MemoryFreeEntry *mfe2,
  54.                                      ULONG column )
  55. {
  56.     switch (column) {
  57.         case 0: return stricmp(mfe1->mfe_Lower, mfe2->mfe_Lower);
  58.         case 1: return stricmp(mfe1->mfe_Upper, mfe2->mfe_Upper);
  59.         case 2: return stricmp(mfe1->mfe_Size, mfe2->mfe_Size);
  60.     }
  61. }
  62.  
  63. static __asm __saveds LONG memmorelist_cmp2func(register __a2 Object *obj, register __a1 struct NList_CompareMessage *msg, register __a0 struct Hook *hook)
  64. {
  65.     LONG cmp;
  66.     struct MemoryFreeEntry *mfe1, *mfe2;
  67.     ULONG col1, col2;
  68.  
  69.     mfe1 = (struct MemoryFreeEntry *)msg->entry1;
  70.     mfe2 = (struct MemoryFreeEntry *)msg->entry2;
  71.     col1 = msg->sort_type & MUIV_NList_TitleMark_ColMask;
  72.     col2 = msg->sort_type2 & MUIV_NList_TitleMark2_ColMask;
  73.  
  74.     if (msg->sort_type == MUIV_NList_SortType_None) return 0;
  75.  
  76.     if (msg->sort_type & MUIV_NList_TitleMark_TypeMask) {
  77.         cmp = memmorelist_cmp2colfunc(mfe2, mfe1, col1);
  78.     } else {
  79.         cmp = memmorelist_cmp2colfunc(mfe1, mfe2, col1);
  80.     }
  81.  
  82.     if (cmp != 0 || col1 == col2) return cmp;
  83.  
  84.     if (msg->sort_type2 & MUIV_NList_TitleMark2_TypeMask) {
  85.         cmp = memmorelist_cmp2colfunc(mfe2, mfe1, col2);
  86.     } else {
  87.         cmp = memmorelist_cmp2colfunc(mfe1, mfe2, col2);
  88.     }
  89.  
  90.     return cmp;
  91. }
  92.  
  93. MakeHook(memmorelist_cmp2hook, memmorelist_cmp2func);
  94.  
  95. static void SetDetails( struct IClass *cl,
  96.                         Object *obj,
  97.                         struct MemoryEntry *me )
  98. {
  99.     struct MemoryDetailWinData *mdwd = INST_DATA(cl, obj);
  100.     UBYTE *tmp;
  101.     static ULONG memtype[]  = { MEMF_PUBLIC, MEMF_CHIP, MEMF_FAST, MEMF_LOCAL,MEMF_24BITDMA, MEMF_KICK, MEMF_CLEAR, MEMF_LARGEST, MEMF_REVERSE, MEMF_TOTAL, MEMF_ANY };
  102.     static UBYTE *memtypetext[] = { "PUBLIC", "CHIP", "FAST", "LOCAL", "24BITDMA", "KICK", "CLEAR", "LARGEST", "REVERSE", "TOTAL" };
  103.  
  104.     if (tmp = tbAllocVecPooled(mdwd->mdwd_MemoryPool, PATH_LENGTH)) {
  105.         ULONG total, inuse;
  106.  
  107.         total = ((ULONG)me->me_Header->mh_Upper) - ((ULONG)me->me_Header->mh_Lower);
  108.         inuse = total - (ULONG)me->me_Header->mh_Free;
  109.  
  110.         set(mdwd->mdwd_MemoryMoreText[0], MUIA_Text_Contents, me->me_Name);
  111.         MySetContents(mdwd->mdwd_MemoryMoreText[1], MUIX_R "$%08lx\n" MUIX_C "%ld\n%s\n" MUIX_R "%lD\n%lD", me->me_Header, me->me_Header->mh_Node.ln_Pri, GetNodeType(me->me_Header->mh_Node.ln_Type), me->me_Header->mh_Free, AvailMem(MEMF_LARGEST | me->me_Header->mh_Attributes));
  112.         MySetContents(mdwd->mdwd_MemoryMoreText[2], MUIX_R "$%08lx\n$%08lx\n$%08lx\n%lD\n%lD", me->me_Header->mh_First, me->me_Header->mh_Lower, me->me_Header->mh_Upper, inuse, total);
  113.  
  114.         tmp[0] = 0x00;
  115.         if (me->me_Header->mh_Attributes) {
  116.             ULONG i;
  117.  
  118.             i = 0;
  119.             while (memtype[i]) {
  120.                 if (me->me_Header->mh_Attributes & memtype[i]) {
  121.                     if (strlen(tmp)) _strcatn(tmp, ", ", PATH_LENGTH);
  122.                     _strcatn(tmp, memtypetext[i], PATH_LENGTH);
  123.                 }
  124.  
  125.                 i++;
  126.             }
  127.         } else {
  128.             stccpy(tmp, "ANY", PATH_LENGTH);
  129.         }
  130.         set(mdwd->mdwd_MemoryMoreText[3], MUIA_Text_Contents, tmp);
  131.  
  132.         DoMethod(mdwd->mdwd_MemoryMoreList, MUIM_NList_Clear);
  133.  
  134.         if (me->me_Header->mh_First) {
  135.             struct MemChunk *mc;
  136.             struct MemoryFreeEntry *mfel;
  137.             ULONG mccnt;
  138.  
  139.             mc = me->me_Header->mh_First;
  140.             mccnt = 0;
  141.             while (mc) {
  142.                 mccnt++;
  143.                 mc = mc->mc_Next;
  144.             }
  145.             mccnt += (mccnt / 10 < 0) ? 10 : (mccnt / 10);
  146.  
  147.             if (mfel = tbAllocVecPooled(mdwd->mdwd_MemoryPool, mccnt * sizeof(struct MemoryFreeEntry))) {
  148.                 struct MemoryFreeEntry *mfe;
  149.                 set(mdwd->mdwd_MemoryMoreList, MUIA_NList_Quiet, TRUE);
  150.  
  151.                 mc = me->me_Header->mh_First;
  152.                 mfe = mfel;
  153.                 while (mc != NULL && mccnt > 0) {
  154.                     _snprintf(mfe->mfe_Lower, sizeof(mfe->mfe_Lower), "$%08lx", mc);
  155.                     _snprintf(mfe->mfe_Upper, sizeof(mfe->mfe_Upper), "$%08lx", (ULONG)mc + mc->mc_Bytes);
  156.                     _snprintf(mfe->mfe_Size, sizeof(mfe->mfe_Size), "%12lD", mc->mc_Bytes);
  157.  
  158.                     InsertBottomEntry(mdwd->mdwd_MemoryMoreList, mfe);
  159.  
  160.                     mfe++;
  161.                     mccnt--;
  162.  
  163.                     mc = mc->mc_Next;
  164.                 }
  165.  
  166.                 set(mdwd->mdwd_MemoryMoreList, MUIA_NList_Quiet, FALSE);
  167.             }
  168.         }
  169.  
  170.         set(obj, MUIA_Window_Title, MyGetChildWindowTitle("MEMORY", me->me_Name, mdwd->mdwd_Title, sizeof(mdwd->mdwd_Title)));
  171.  
  172.         tbFreeVecPooled(mdwd->mdwd_MemoryPool, tmp);
  173.     }
  174. }
  175.  
  176. static ULONG __saveds mNew( struct IClass *cl,
  177.                             Object *obj,
  178.                             struct opSet *msg )
  179. {
  180.     APTR memmoretext[4], memmorelist;
  181.  
  182.     if (obj = (Object *)DoSuperNew(cl, obj,
  183.         MUIA_HelpNode, MemoryText,
  184.         MUIA_Window_ID, MakeID('.','M','E','M'),
  185.         WindowContents, HGroup,
  186.             Child, VGroup, MUIA_Group_SameWidth, TRUE,
  187.                 Child, MyLabel2("Name:"),
  188.                 Child, MyLabel2("Address:\nPri:\nType:\nFree:\nLargest:"),
  189.                 Child, MyLabel2("Attributes:"),
  190.                 Child, MyLabel2("\nChunks:"),
  191.                 Child, MyVSpace(0),
  192.             End,
  193.             Child, VGroup, MUIA_Group_SameWidth, TRUE,
  194.                 Child, memmoretext[0] = MyTextObject(),
  195.                 Child, HGroup,
  196.                     Child, memmoretext[1] = MyTextObject2(),
  197.                     Child, MyLabel("First:\nLower:\nUpper:\nInUse:\nTotal:"),
  198.                     Child, memmoretext[2] = MyTextObject2(),
  199.                 End,
  200.                 Child, memmoretext[3] = MyTextObject(),
  201.  
  202.                 Child, memmorelist = MyNListviewObject(MakeID('.','M','L','V'), "BAR,BAR,BAR P=" MUIX_R, NULL, NULL, &memmorelist_dsp2hook, &memmorelist_cmp2hook, FALSE),
  203.             End,
  204.         End,
  205.         TAG_MORE, msg->ops_AttrList))
  206.     {
  207.         struct MemoryDetailWinData *mdwd = INST_DATA(cl, obj);
  208.         APTR parent;
  209.  
  210.         CopyMem(memmoretext, mdwd->mdwd_MemoryMoreText, sizeof(mdwd->mdwd_MemoryMoreText));
  211.         mdwd->mdwd_MemoryMoreList = memmorelist;
  212.         mdwd->mdwd_MemoryPool = tbCreatePool(MEMF_CLEAR | MEMF_PUBLIC, 4096, 4096);
  213.  
  214.         parent = (APTR)GetTagData(MUIA_Window_ParentWindow, (ULONG)NULL, msg->ops_AttrList);
  215.  
  216.         set(obj, MUIA_Window_ActiveObject, memmorelist);
  217.  
  218.         DoMethod(parent, MUIM_Window_AddChildWindow, obj);
  219.         DoMethod(obj,    MUIM_Notify, MUIA_Window_CloseRequest, TRUE, MUIV_Notify_Application, 5, MUIM_Application_PushMethod, parent, 2, MUIM_Window_RemChildWindow, obj);
  220.     }
  221.  
  222.     return (ULONG)obj;
  223. }
  224.  
  225. static ULONG __saveds mDispose( struct IClass *cl,
  226.                                 Object *obj,
  227.                                 struct opSet *msg )
  228. {
  229.     struct MemoryDetailWinData *mdwd = INST_DATA(cl, obj);
  230.  
  231.     set(obj, MUIA_Window_Open, FALSE);
  232.     DoMethod(mdwd->mdwd_MemoryMoreList, MUIM_NList_Clear);
  233.  
  234.     tbDeletePool(mdwd->mdwd_MemoryPool);
  235.  
  236.     return (DoSuperMethodA(cl, obj, msg));
  237. }
  238.  
  239. static ULONG __saveds mSet( struct IClass *cl,
  240.                             Object *obj,
  241.                             Msg msg )
  242. {
  243.     struct TagItem *tags, *tag;
  244.  
  245.     for (tags = ((struct opSet *)msg)->ops_AttrList; tag = NextTagItem(&tags); ) {
  246.         switch (tag->ti_Tag) {
  247.             case MUIA_Window_ParentWindow:
  248.                 DoMethod(obj, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, MUIV_Notify_Application, 5, MUIM_Application_PushMethod, (APTR)tag->ti_Data, 2, MUIM_Window_RemChildWindow, obj);
  249.                 break;
  250.  
  251.             case MUIA_MemoryDetailWin_Memory:
  252.                 SetDetails(cl, obj, (struct MemoryEntry *)tag->ti_Data);
  253.                 break;
  254.         }
  255.     }
  256.  
  257.     return (DoSuperMethodA(cl,obj,msg));
  258. }
  259.  
  260. ULONG __asm __saveds MemoryDetailWinDispatcher( register __a0 struct IClass *cl,
  261.                                                 register __a2 Object *obj,
  262.                                                 register __a1 Msg msg )
  263. {
  264.     switch (msg->MethodID) {
  265.         case OM_NEW:     return (mNew(cl, obj, (APTR)msg));
  266.         case OM_DISPOSE: return (mDispose(cl, obj, (APTR)msg));
  267.         case OM_SET:     return (mSet(cl, obj, (APTR)msg));
  268.     }
  269.  
  270.     return (DoSuperMethodA(cl, obj, msg));
  271. }
  272.  
  273.